package com.atguigu.config;

import com.atguigu.bean.Person;
import com.atguigu.service.BookService;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

//配置类==配置文件
@Configuration //告诉Spring这是一个配置类
//value:配置包扫描路径,同标签中的一样
//excludeFilters = Filter[]: 指定排除规则,是传递进去@Filter的数组,同时指定排除哪些组件
//includeFilters = Filter[]: 指定扫描的时候包含哪些组件
//useDefaultFilters: 在使用 use-default-filters 属性时要分清楚需要扫描哪些包，是不是需要使用默认的 Filter 进行扫描。楼主稍微总结一下，
// 即 use-default-filters="false" 需要和 context:include-filter 一起使用，而不能和 context:exclude-filter 属性一起使用。
@ComponentScan(value = "com.atguigu", excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})
}, includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})}
        , useDefaultFilters = false)
//java8之后可以创建多个@ComponentScan来指定多种不同的扫描策略
//也可以用@ComponentScans() :来指定多个ComponentScan
//type:  和classes属性连用
//          1.ANNOTATION属性,根据注解来扫描
//          2.ASSIGNABLE_TYPE,安装给定的类型来配置
@ComponentScans(value = {
        @ComponentScan(value = "com.atguigu", excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})
        }, includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})}
                , useDefaultFilters = false),
        @ComponentScan(value = "com.atguigu", excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {BookService.class})
        }, includeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {BookService.class})}
                , useDefaultFilters = false)
})
public class MainConfig {

    //给容器种注册一个Bean;类型为返回值的类型,id默认是用方法名作为id.

    /**
     * 如果在@Bean里面指定,指定的值就是这个bean的id
     * 如果没有在@Bean里面指定,则id就是方法名
     *
     * @return
     */
    @Bean("person")
    public Person getPerson() {
        return new Person("lisi", 20);
    }

}
